<?php
/**
 * Zend_Service_Netflix_Rating Class
 *
 * @author Armando Padilla, armando_padilla_81@yahoo.com
 * @package Zend_Service_Netflix
 * 
 */ 
require_once "Utils.php";
 
class Zend_Service_Netflix_Rating { 
	
	/**
	 * Rating Id.
	 *
	 * @var String
	 */
	public $id;
	
	/**
	 * User Rating.
	 *
	 * @var String
	 */
	public $userRating;
	
	/**
	 * Predicted Rating.
	 *
	 * @var String
	 */
	public $predictedRating;

	
	/**
	 * Title the rating belongs to.
	 *
	 * @var String
	 */
	public $title;
	
	/**
	 * Title API URL Ref.
	 *
	 * @var String
	 */
	public $titleIDAsURL;
	
	/**
	 * Title id.
	 *
	 * @var String
	 */
	public $titleID;
	
	public function __construct(){}
	
	/**
	 * Loads the data for the object
	 *
	 * @param SimpleXMLElement $simpleXMLObject
	 */
	public function loadXML(SimpleXMLElement $ratingXML){
		
		//Intialize and Set all variables
		$this->userRating      		= (string)$ratingXML->user_rating;
		$this->predictedRating 		= (string)$ratingXML->predicted_rating;
		$this->title           		= (string)$ratingXML->title['regular'];
		$this->ratingId 	   		= (string)$ratingXML->id;
		
		//Get the title id.
		$xml = simplexml_load_string($ratingXML->asXML());
		
		$titleIdInfo = $xml->xpath("link[@rel='http://schemas.netflix.com/catalog/title']");
		
		foreach($titleIdInfo as $info){
			
			$this->titleIDAsURL = (string)$info['href'];
			$this->titleId 	    = Zend_Service_Netflix_Utils::parseTitleId((string)$info['href']);
		
		}
		
	}
	
}
?>